<?php
namespace app\index\controller;

use think\Controller;

class Login extends Controller
{
    public function login()
    {

        return view();
    }


    public function checklogin(){

        $post = input('post.');

//        print_r($post);

        $ad = validate('ad');

        if(!$ad->check($post)){
            $this->error($ad->getError());
            die;
        }

        $count = db('user')->where(['user'=>$post['name'],'pwd'=>$post['password']])->count();

        if ($count){
            session('name',$post['name']);
            $this->success('登录成功','index/index');
            die;
        }
        else{
            $this->error('登录失败');
        }

    }

    public function loginout(){

        session('name',null);
        $this->success('退出成功','login');

    }


}